let userData = {
  avatar: 'static/logo.png',
  name: '用户名称',
  bio: '用户简介',
  achievements: [
    { id: 1, name: '成就1', description: '成就1描述' },
    { id: 2, name: '成就2', description: '成就2描述' }
  ],
  totalExperiencePoints: 1000,
  lifeExperiencePoints: 500,
  communityLikes: 20,
  daysOfCompletion: 30
};

let products = [
  { id: 1, name: '虚拟金币', price: 10, description: '100个虚拟金币', stock: 100, effect: '增加100个虚拟金币', purchaseLimit: 10 },
  { id: 2, name: '虚拟商品1', price: 100, description: '虚拟商品1描述', stock: 10, effect: '效果1', purchaseLimit: 1 },
  { id: 3, name: '虚拟商品2', price: 200, description: '虚拟商品2描述', stock: 5, effect: '效果2', purchaseLimit: 2 },
  { id: 4, name: '真实商品1', price: 300, description: '真实商品1描述', stock: 20, effect: '效果3', purchaseLimit: 1 }
];

let nextProductId = 4;

export function getUser() {
  return userData;
}

export function updateUser(updatedUser) {
  userData = { ...userData, ...updatedUser };
}

export function getProducts() {
  return products;
}

export function purchaseProduct(productId) {
  const product = products.find(p => p.id === productId);
  if (product && product.stock > 0) {
    product.stock -= 1;
    return true;
  }
  return false;
}

export function addProduct(newProduct) {
  newProduct.id = nextProductId++;
  products.push(newProduct);
  return newProduct;
}
